package com.yanqu.road.server.cmd.activity.busyfarming;

import com.yanqu.road.entity.activity.busyfarming.BusyFarmingUserData;
import com.yanqu.road.pb.activity.BusyFarmingProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.busyfarming.BusyFarmingPb;
import com.yanqu.road.server.manger.activity.busyfarming.BusyFarmingMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_BUSY_FARMING_USER_DATA,desc = "请求玩家数据")
public class BusyFarmingUserDataCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(BusyFarmingMgr.getShowTimeActivityId() == 0){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }

        BusyFarmingUserData userData = BusyFarmingMgr.getBusyFarmingUserData(player.getUserId());
        if(userData != null){
            BusyFarmingProto.BusyFarmingUserDataRespMsg.Builder respMsg = BusyFarmingProto.BusyFarmingUserDataRespMsg.newBuilder();
            respMsg.setUserData(BusyFarmingPb.getUserDataBuilder(userData, true));
            respMsg.setActivityId(BusyFarmingMgr.getShowTimeActivityId());
            player.sendPacket(Protocol.U_BUSY_FARMING_USER_DATA, respMsg);
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
